package router

import "github.com/gin-gonic/gin"

type (
	Route struct {
		Method  string
		Path    string
		Handler gin.HandlerFunc
	}

	RouteGroup struct {
		BasePath   string
		Middleware *[]gin.HandlerFunc
		Routes     []*Route
	}
)

func LoadAndCreateRouter(groups []*RouteGroup) *gin.Engine {
	r := gin.New()

	for _, rg := range groups {
		group := r.Group(rg.BasePath)
		group.Use(*rg.Middleware...)
		for _, route := range rg.Routes {
			group.Handle(route.Method, route.Path, route.Handler)
		}
	}

	return r
}
